<?php

class cPoint3 extends cMatrix
{	
	public function __construct($x = 0,$y = 0,$z = 0,$w = 1)
	{
		parent::__construct(1,4);

		$this->setX($x);
		$this->setY($y);
		$this->setZ($z);
		$this->setW($w);
	}	

	public function getX()
	{
		return $this->get(0,0);
	}
	
	public function setX($value)
	{
		$this->set(0,0,$value);
	}
	
	public function X($offset=0)
	{
		return $this->alter(0,0,$offset); 
	}
	
	public function getY()
	{
		return $this->get(0,1);
	}

	public function setY($value)
	{
		$this->set(0,1,$value);
	}
	
	public function Y($offset=0)
	{
		return $this->alter(0,1,$offset); 
	}	
	
	public function getZ()
	{
		return $this->get(0,2);
	}	
	
	public function setZ($value)
	{
		$this->set(0,2,$value);
	}
	
	public function Z($offset=0)
	{
		return $this->alter(0,2,$offset); 
	}	
	
	
	public function getW()
	{
		return $this->get(0,3);
	}
	
	public function setW($value)
	{
		$this->set(0,3,$value);
	}	
	
	public function W($offset=0)
	{
		return $this->alter(0,1,$offset); 
	}	
	

	public function magnitude()
	{
		return ($this->getX() * $this->getX()) + ($this->getY() * $this->getY() + ($this->getZ() * $this->getZ()));
	}
		
	public function normalise()
	{
		$length = $this->length();
		return new cPoint3($this->getX() / $length, $this->getY() / $length,$this->getZ() / $length);
	}	
	
	public function __toString()
	{
		$output = "";
		$output .= "X: ".$this->getX()."\n";
		$output .= "Y: ".$this->getY()."\n";
		$output .= "Z: ".$this->getZ()."\n";
		$output .= "W: ".$this->getW()."\n";
		return $output;
	}
}

?>